package com.moran.controller;

import com.moran.tools.UserTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 工具调用controller
 *
 */
@Slf4j
@RestController
public class ToolsController {

    @Autowired
    private UserTools userTools;

    private final ChatClient chatClient;

    public ToolsController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    /**
     * 工具调用
     *
     * @param input
     * @return
     */
    @PostMapping("/tools")
    public String tools(String input) {
        String response = chatClient.prompt(input)
                .tools(userTools)
                .call()
                .content();

        return response;
    }

}
